package com.cqq.base.filter;

import com.cqq.auth.service.bean.UserBean;
import com.cqq.auth.shiro.AuthUtil;
import com.cqq.pro.util.PropertiesUtil;

/**
 * <h3>FMANGER 上下文</h3>
 * 
 * @author GUOQIANG
 * @version 1.0.0
 */
public class FMContext {
	private static final ThreadLocal<FMContext> fmContext = new ThreadLocal<FMContext>();

	private String systemCode;
	private Integer userId;

	public String getSystemCode() {
		return systemCode;
	}

	public void setSystemCode(String systemCode) {
		this.systemCode = systemCode;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public Integer getCustomerId() {
		String custId = PropertiesUtil.getConfigValue("system.cid");
		return (custId!=null&&custId.trim().length()>0)?Integer.parseInt(custId):null;
	}

	//########################## Business Method ##########################//

	//########################## Context Static Method ##########################//

	public static UserBean getLoginUser() {
		return AuthUtil.getLoginUser();
	}

	//########################## Context Method (Ignore) ##########################//

	public static FMContext getCurrent() {
		FMContext context = fmContext.get();

		if (context == null) {
			context = new FMContext();
			setCurrent(context);
		}

		return context;
	}

	public static void setCurrent(FMContext context) {
		fmContext.set(context);
	}

	public static void resetCurrent() {
		fmContext.remove();
	}
}